<template>
	<!-- 小纸条/好友列表 -->
	<view class="user-list p-20 flex items-center border-b border-gray-100" hover-class="bg-gray-100" @click="goToChat">
		<image class="user-img mr-20 rounded-full" :src="item.friendAvatar" mode="aspectFill" @click.stop="goToDetail(item.friendId)"></image>
		<view class="flex flex-col flex-1">
			<text class="text-30 font-bold mb-10">{{item.friendName}}</text>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			item: {
				type: Object,
				default: () => ({})
			}
		},
		methods: {
			goToChat() {
				// 获取当前登录用户ID（示例使用 uni.getStorageSync）
				const currentUserId = getApp().globalData.userId;
	
				// 判断是否是自己
				if (this.item.friendId === currentUserId) {
					return; // 如果是自己，不跳转
				}
				if (this.item.isVerify) {
					uni.navigateTo({
						url: `/pages/paper/friend-verify/index`
					});
				} else {
					uni.navigateTo({
						url: `/pages/paper/chat?username=${encodeURIComponent(this.item.friendName)}&friendId=${this.item.friendId}`
					});
				}
			},
			goToDetail(userId) {
				const currentUserId = getApp().globalData.userId;
					
				// 判断是否是自己
				if (userId === currentUserId) {
					uni.navigateTo({
						url: '/pages/mine/user-space'
					});
				}else{
					uni.navigateTo({
						url: `/pages/paper/friend_profile?userId=${userId}`
					});
				}
			}
		}
	}
	
</script>

<style lang="scss" scoped>
	// 用户列表
	.user-list {
		.user-img {
			width: 100rpx;
			height: 100rpx;
		}

	
	}
</style>